package com.base.code;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yuanzheng
 * @date 2020/10/5-16:01
 */
public class TestDateFormat {
    public static void main(String[] args) throws ParseException {
        String dateStr = "2020-01-13 12:12";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = sdf.parse(dateStr);
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int week = calendar.get(Calendar.WEEK_OF_YEAR);
        System.out.println("" + year );
        System.out.println("" + month );
        System.out.println( "" + week);

        Calendar calendar1 = Calendar.getInstance();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        calendar1.add(Calendar.DATE, -3);
        String three_days_ago = sdf1.format(calendar1.getTime());
        System.out.println(three_days_ago);
    }


}
